//
//  LGPatientEvaluateController.m
//  BreathTrainingTool
//
//  Created by 1234 on 2024/7/15.
//  患者 -- 评估列表

#import "LGPatientEvaluateController.h"
//详情
#import "LGEvaluateDetailController.h"
#import "LGPatientDetailEvaluateCell.h"

@interface LGPatientEvaluateController ()<UITableViewDelegate,UITableViewDataSource>
/**   */
@property (nonatomic , strong)UITableView *tableView;

/**   */
@property (nonatomic , strong)NSArray *dataArray;

@end

@implementation LGPatientEvaluateController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.title = @"全部评估报告";
    self.view.backgroundColor = [UIColor colorWithString:@"#F3F1FC"];
    [self.view addSubview:self.tableView];
    [self emptyViewWithSuperView:self.view frame:self.tableView.frame];
    [self requestData];
}

-(void)requestData{
    [RequestUtil withGET:@"/brbot-scale/answer/getScaleAnswerByGroup/day" parameters:@{@"patientId":self.patientid} header:YES success:^(NSInteger code, NSString *message, id returnData) {
        self.isfirst = NO;
        [self.emptyView stopBufferAction];
        if (code == 200) {
            self.dataArray = returnData;
            [self.tableView reloadData];
        }
        if(self.dataArray.count == 0){
            [self.emptyView showViewWithImage:@"emptyView2" content:@"暂无评估" offset:0];
        }
    } error:^(NSError *error) {
        self.isfirst = NO;
        [self.emptyView stopBufferAction];
        if(self.dataArray.count == 0){
            [self.emptyView showViewWithImage:@"emptyView2" content:@"暂无评估" offset:0];
        }
    }];
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return self.dataArray.count;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    NSArray *tempArray = self.dataArray[section][@"list"];
    return tempArray.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    NSArray *tempArray = self.dataArray[indexPath.section][@"list"];
    LGPatientDetailEvaluateCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.dataDic = tempArray[indexPath.row];
    if (tempArray.count<=1) {
        cell.type = LGPositionTypeSingle;
    }else if (indexPath.row == 0){
        cell.type = LGPositionTypeTop;
    }else if (indexPath.row == tempArray.count-1){
        cell.type = LGPositionTypeBottom;
    }else{
        cell.type = LGPositionTypeMiddle;
    }
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    NSDictionary *tempDic = self.dataArray[indexPath.section][@"list"][indexPath.row];
    LGEvaluateDetailController *controller = [[LGEvaluateDetailController alloc]init];
    controller.scaleid = LGNSString(tempDic[@"scaleId"]);
    controller.batchid = LGNSString(tempDic[@"batchNo"]);
    controller.bizid = LGNSString(tempDic[@"scaleIdByDicBizId"]);
    controller.time = LGNSString(tempDic[@"createTime"]);
    controller.score = LGNSString(tempDic[@"score"]);
    controller.patientid = self.patientid;
    [self.navigationController pushViewController:controller animated:YES];
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return viewPix(40);
}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UIView *headView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, Screen_W, viewPix(40))];
    UILabel *titleLabel = [UILabel lableWithText:LGNSString(self.dataArray[section][@"day"]) colorString:@"#2B2A37" textFont:LGFont(14) textAlignment:NSTextAlignmentLeft lines:1];
    titleLabel.frame = CGRectMake(viewPix(17), viewPix(16), Screen_W-viewPix(34), viewPix(20));
    [headView addSubview:titleLabel];
    return headView;
}

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 0.01;
}

-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    UIView *footView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, Screen_W, 0.01)];
    return footView;
}


-(UITableView *)tableView{
    if(!_tableView){
        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, Screen_W, Screen_H-topBarHeight) style:UITableViewStyleGrouped];
        [_tableView registerClass:[LGPatientDetailEvaluateCell class] forCellReuseIdentifier:@"cell"];
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableView.rowHeight = UITableViewAutomaticDimension;
        _tableView.backgroundColor = [UIColor colorWithString:@"#F3F1FC"];
        _tableView.showsVerticalScrollIndicator = NO;
        _tableView.dataSource = self;
        _tableView.delegate = self;
        _tableView.tableHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, Screen_W, 0.01)];
    }
    return _tableView;
}
     
@end
